home *** CD-ROM | disk | FTP | other *** search
/ Champak 106 / Vol 106.iso / games / insuranc.swf / scripts / __Packages / Enemy.as < prev    next >
Encoding:
Text File  |  2010-04-12  |  8.9 KB  |  331 lines

  1. class Enemy extends Car
  2. {
  3.    var distance;
  4.    var sEnemy;
  5.    var energy;
  6.    var deadDelay;
  7.    var dropTime;
  8.    var runTime;
  9.    var bOnScreen;
  10.    var mcCar;
  11.    var mcEnergy;
  12.    var mcCanvas;
  13.    var pos;
  14.    var width;
  15.    var turnDelay;
  16.    var turnTime;
  17.    var autoTurnFactor;
  18.    var turnDir;
  19.    var bDestroyed;
  20.    var vel;
  21.    var velMod;
  22.    var height;
  23.    var mcDamage;
  24.    var bFromWeapon;
  25.    var maxVel;
  26.    var blinkInd;
  27.    var frame;
  28.    var firstFrame;
  29.    function Enemy(distanceNew, sEnemyNew, newPos, newVel, mcCanvasNew, depth)
  30.    {
  31.       super("enemy " + sEnemyNew,newPos,newVel,mcCanvasNew,depth);
  32.       this.distance = distanceNew;
  33.       this.sEnemy = sEnemyNew;
  34.       this.energy = 10;
  35.       this.deadDelay = 0;
  36.       this.dropTime = 40;
  37.       this.runTime = 0;
  38.       this.bOnScreen = false;
  39.       this.mcCar.gotoAndStop("alive");
  40.       this.mcEnergy = this.mcCanvas.attachMovie("boss energy","mcEnergy",depth + 1);
  41.    }
  42.    function setFramesRange(Void)
  43.    {
  44.    }
  45.    function step(player, plDist, bmpShoulder)
  46.    {
  47.       if(plDist > this.distance)
  48.       {
  49.          super.step(player.pos,player.vel,bmpShoulder);
  50.          var _loc6_ = player.pos.x - this.pos.x;
  51.          var _loc4_ = player.pos.y - this.pos.y;
  52.          if(Math.abs(_loc6_) < this.width && this.turnDelay > 15)
  53.          {
  54.             this.turnDelay = 15;
  55.             this.turnTime = 15;
  56.             this.autoTurnFactor = 5;
  57.             this.turnDir = Math.random() >= 0.5 ? 1 : -1;
  58.          }
  59.          if(!this.bDestroyed)
  60.          {
  61.             if(player.vel.y < 12)
  62.             {
  63.                this.vel.y = 12;
  64.             }
  65.             else if(player.pos.y + 20 < this.pos.y)
  66.             {
  67.                _loc4_ = this.pos.y - player.pos.y;
  68.                if(_loc4_ < 100 || this.runTime > 0)
  69.                {
  70.                   if(this.runTime == 0)
  71.                   {
  72.                      this.runTime = 10 + Math.round(20 * Math.random());
  73.                      var _loc5_ = 24 - player.vel.y;
  74.                      this.velMod = player.vel.y - 2 + _loc5_ * Math.random();
  75.                   }
  76.                   else
  77.                   {
  78.                      this.runTime = this.runTime - 1;
  79.                   }
  80.                   this.vel.y = this.velMod;
  81.                }
  82.                else
  83.                {
  84.                   this.vel.y = player.vel.y - 1;
  85.                }
  86.             }
  87.             else
  88.             {
  89.                this.vel.y = player.vel.y + 5;
  90.             }
  91.          }
  92.          if(this.pos.y < -50)
  93.          {
  94.             if(this.bDestroyed)
  95.             {
  96.                this.die();
  97.             }
  98.             else
  99.             {
  100.                this.pos.y = -50;
  101.                this.vel.y = player.vel.y;
  102.                this.onOutOfScreenV();
  103.             }
  104.          }
  105.          else if(this.pos.y > Game.screenH + 50)
  106.          {
  107.             if(this.bDestroyed)
  108.             {
  109.                this.die();
  110.             }
  111.             else
  112.             {
  113.                this.pos.y = Game.screenH + 50;
  114.                this.vel.y = 5;
  115.                this.onOutOfScreenV();
  116.             }
  117.          }
  118.          if(this.pos.y > -50 && this.pos.y < Game.screenH + 50)
  119.          {
  120.             this.bOnScreen = true;
  121.          }
  122.          if(this.bOnScreen)
  123.          {
  124.             if(this.dropTime > 0)
  125.             {
  126.                this.dropTime = this.dropTime - 1;
  127.             }
  128.             else if(!this.bDestroyed)
  129.             {
  130.                this.dropTime = 60 + Math.round(60 * Math.random());
  131.                Game.getInstance().createObstacle();
  132.             }
  133.          }
  134.       }
  135.    }
  136.    function draw(Void)
  137.    {
  138.       this.mcCar._x = this.pos.x;
  139.       this.mcCar._y = Game.screenH - this.pos.y;
  140.       this.mcEnergy._x = this.mcCar._x;
  141.       this.mcEnergy._y = this.mcCar._y - this.height / 2 - 10;
  142.       this.mcEnergy.mcBar._xscale += (100 * this.energy / 10 - this.mcEnergy.mcBar._xscale) * 0.4;
  143.       this.mcDamage._x = this.mcCar._x;
  144.       this.mcDamage._y = this.mcCar._y;
  145.       if(this.bDestroyed)
  146.       {
  147.          if(this.sEnemy == "rac" || !this.bFromWeapon)
  148.          {
  149.             this.mcCar._rotation += this.vel.y >= 2 ? this.vel.y * 3 : 6;
  150.          }
  151.          else if(this.sEnemy == "aa")
  152.          {
  153.             this.mcCar._x += 4 * (1 - 2 * Math.random());
  154.          }
  155.       }
  156.       else
  157.       {
  158.          this.mcCar._rotation = this.vel.x * Math.ceil(this.vel.y / this.maxVel);
  159.       }
  160.    }
  161.    function getDamage(value)
  162.    {
  163.       if(this.blinkInd == 0)
  164.       {
  165.          this.blinkInd = 10;
  166.          if(value != undefined)
  167.          {
  168.             this.energy -= value;
  169.          }
  170.          else
  171.          {
  172.             this.energy -= 1;
  173.          }
  174.       }
  175.       if(this.energy <= 0 && !this.bDestroyed)
  176.       {
  177.          this.energy = 0;
  178.          this.vel.y /= 2;
  179.          if(!(!this.bFromWeapon && this.sEnemy == "churchil"))
  180.          {
  181.             this.mcCar.gotoAndStop("dead");
  182.          }
  183.          this.mcEnergy._visible = false;
  184.          this.bDestroyed = true;
  185.          Game.getInstance().protectPlayer();
  186.          switch(this.sEnemy)
  187.          {
  188.             case "directLine":
  189.                this.deadDelay = 7;
  190.                break;
  191.             case "churchil":
  192.                this.blinkInd = 0;
  193.                break;
  194.             case "elephant":
  195.                this.deadDelay = 6;
  196.                break;
  197.             case "lloyd":
  198.                this.deadDelay = 6;
  199.          }
  200.          if(this.bFromWeapon)
  201.          {
  202.             Game.getInstance().addPoints(5000);
  203.             Game.getInstance().showBonus();
  204.          }
  205.          else
  206.          {
  207.             Game.getInstance().addPoints(1000);
  208.             Game.getInstance().showPoints(this.pos,1000);
  209.          }
  210.       }
  211.       else if(this.energy > 0)
  212.       {
  213.          this.bFromWeapon = false;
  214.          if(this.sEnemy == "directLine" || this.sEnemy == "sainsbury")
  215.          {
  216.             var _loc2_ = this.mcCar.getDepth() + 2;
  217.             this.mcDamage = this.mcCanvas.attachMovie("car damage","mcDamage" + _loc2_,_loc2_);
  218.             this.mcDamage.gotoAndStop(this.sEnemy);
  219.          }
  220.       }
  221.    }
  222.    function die(Void)
  223.    {
  224.       Game.getInstance().onEnemyDead();
  225.    }
  226.    function remove(Void)
  227.    {
  228.       this.mcCar.removeMovieClip();
  229.       this.mcEnergy.removeMovieClip();
  230.       this.mcDamage.removeMovieClip();
  231.       false;
  232.    }
  233.    function modifyVelocity(plVel)
  234.    {
  235.       if(this.deadDelay > 0)
  236.       {
  237.          this.deadDelay = this.deadDelay - 1;
  238.          this.vel.y = plVel.y;
  239.       }
  240.       else if(this.bFromWeapon)
  241.       {
  242.          switch(this.sEnemy)
  243.          {
  244.             case "tesco":
  245.                this.vel.x = 0;
  246.                this.vel.y = plVel.y - 5;
  247.                break;
  248.             case "directLine":
  249.                this.vel.x = 0;
  250.                this.vel.y = plVel.y - 5;
  251.                break;
  252.             case "elephant":
  253.                this.vel.x = -3;
  254.                this.vel.y = plVel.y + 15;
  255.                break;
  256.             case "sainsbury":
  257.                this.vel.x = 0;
  258.                this.vel.y = plVel.y - 5;
  259.                break;
  260.             case "churchil":
  261.                this.vel.x = 0;
  262.                this.vel.y = plVel.y - 20;
  263.                break;
  264.             case "moreThan":
  265.                this.vel.x = 0;
  266.                this.vel.y = plVel.y + 15;
  267.                break;
  268.             case "asda":
  269.                this.vel.x -= 20;
  270.                this.vel.y = plVel.y + 2;
  271.                break;
  272.             case "lloyd":
  273.                this.vel.x = 0;
  274.                this.vel.y = plVel.y + 15;
  275.                break;
  276.             default:
  277.                this.vel.y = plVel.y - 10;
  278.                if(this.pos.x > 275)
  279.                {
  280.                   this.vel.x = 5;
  281.                   break;
  282.                }
  283.                this.vel.x = -5;
  284.                break;
  285.          }
  286.       }
  287.       else if(this.pos.x > 275)
  288.       {
  289.          this.vel.x = 5;
  290.       }
  291.       else
  292.       {
  293.          this.vel.x = -5;
  294.       }
  295.    }
  296.    function onOutOfScreenV(Void)
  297.    {
  298.       this.bOnScreen = false;
  299.    }
  300.    function onOutOfScreenH(Void)
  301.    {
  302.       if(!this.bDestroyed)
  303.       {
  304.          this.pos.y = -50;
  305.          this.pos.x = 275;
  306.       }
  307.       else
  308.       {
  309.          this.mcCar._visible = false;
  310.          this.mcEnergy._visible = false;
  311.          this.die();
  312.       }
  313.    }
  314.    function checkWeapon(mcWeapon)
  315.    {
  316.       var _loc2_ = Game.getInstance().sEnemy;
  317.       if((_loc2_ == "directLine" || _loc2_ == "aa") && mcWeapon.hitTest(this.mcCar._x,this.mcCar._y) || _loc2_ != "directLine" && _loc2_ != "aa" && mcWeapon.hitTest(this.mcCar))
  318.       {
  319.          this.bFromWeapon = true;
  320.          var _loc3_ = !Application.bEasy ? 3 : 5;
  321.          this.getDamage(_loc3_);
  322.          this.setFramesRange();
  323.          this.frame = this.firstFrame;
  324.          if(_loc2_ == "sainsbury")
  325.          {
  326.             Game.getInstance().removeShot();
  327.          }
  328.       }
  329.    }
  330. }
  331.